package com.linzm.leetcode.mid.tree.递归遍历;

import java.util.ArrayList;
import java.util.List;

/**
 * @Author zimingl
 * @Date 2023/2/19 12:58
 * @Description: TODO
 */
public class PostorderTraversal145 {
    public static void main(String[] args) {
        PostorderTraversal145 postorderTraversal145 = new PostorderTraversal145();
        List<Integer> list = postorderTraversal145.postorderTraversal(TreeNode.getTree());
        System.out.println(list);
    }

    private List<Integer> postorderTraversal(TreeNode root) {
        List<Integer> list = new ArrayList<>();
        postorder(root, list);
        return list;
    }

    private void postorder(TreeNode root, List<Integer> list) {
        if (root == null) {
            return;
        }
        postorder(root.left, list);
        postorder(root.right, list);
        list.add(root.val);
    }
}
